﻿cmake_minimum_required(VERSION 3.5)

set(CMAKE_CXX_STANDARD 17)
project(guild-service-proxy)

IF (MSVC)
ELSE()
  SET(CMAKE_CXX_FLAGS "-m64 -g -O2 -std=c++17 -Wall -Wno-unused-variable -fnon-call-exceptions")
  set(CMAKE_CXX_COMPILER "g++")
ENDIF()

include_directories(
    ${PROJECT_SOURCE_DIR}/../../../../..
    ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/include
    ${PROJECT_SOURCE_DIR}/../../../../src/include/root
    ${PROJECT_SOURCE_DIR}/../../../../thirdparty/include
)

aux_source_directory(. SRC_FILES)

if(WIN32)
	message("WIN32")
    link_directories(${PROJECT_SOURCE_DIR}/../../../../../../win-proj/x64/Debug) #service-box.lib
else()
    message("LINUX")
    link_directories(${PROJECT_SOURCE_DIR}/../../../../../lib) #libservice_box.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/root) #librpc.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/linux) #libprotobuf.a
    link_directories(/usr/local/lib) #libhiredis.a libz.a libcurl.a libhashtable.a libzookeeper.a
endif()

add_executable (${PROJECT_NAME} ${SRC_FILES})

#静态链接库目录
if (MSVC)
	message("WIN32")
foreach(var
  CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${var} MATCHES "/MD")
  string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
endif()
endforeach()
    set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/EHsc /W3")

    target_link_libraries(${PROJECT_NAME}
        service-box.lib
        ${PROJECT_SOURCE_DIR}/../../../../lib/root/Debug/librpc.a
        ${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/windows/debug/libprotobufd.lib
        ${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/windows/release/libprotobuf.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/zookeeper.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hashtable.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hiredis.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/Win32_Interop.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/libcurl.a
        # libz.a

        wldap32.lib
        ws2_32.lib
        psapi.lib
    )
ELSE()
    message("LINUX")
    target_link_libraries(${PROJECT_NAME}
        libservice_box.a
        librpc.a
        libprotobuf.a
        libzookeeper.a
        libhashtable.a
        libhiredis.a
        libcurl.a
        libz.a
        -lpthread
        -ldl
    )
ENDIF()